<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="p" uri="/WEB-INF/tld/privilege.tld" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改需求</title>
<base href="<%=basePath%>" />
<link rel="stylesheet" type="text/css" href="css/common.css" />
<link rel="stylesheet" href="<%=basePath%>/js/uploadify/css/uploadify.css" type="text/css"></link>
<link type="text/css" href="js/mcdropdown/css/jquery.mcdropdown.css" rel="stylesheet" media="all" />
<script type="text/javascript" src="js/mcdropdown/lib/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/jquery.form.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/mcdropdown/lib/jquery.mcdropdown.js"></script>
<script type="text/javascript" src="js/mcdropdown/lib/jquery.bgiframe.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/uploadify/jquery.uploadify-3.1.min.js"></script>
<script language="JavaScript" type="text/javascript" src="<%=basePath%>js/my97/WdatePicker.js" defer="defer"></script>
<style type="text/css">
	fieldset,legend,form,table,tr,td,textarea {margin: 0;padding: 0}
	form label {font-weight: bold;}
	table {margin: 10px 10px;}
	td {line-height: 25px;}
	input[type="text"] {width: 250px;}
	input[type="password"] {width: 250px;}
	input[type="textarea"] {width: 250px;}
	.divlist {float: left;height: 100%;width: 60%;}
	.divcomment {float: left;height: 100%;width: 40%;}
	.word{line-height: 120%;word-break:break-all}
	.white_content {display: none; position: absolute;top: 30%;left: 30%; width: 30%; height: 40%;padding: 6px; border: 6px solid #FFFFFF;background-color: white; z-index:1002; overflow: auto;}
    .T_iframe   {background: #33393C;position: absolute;width: 100%; height: 100%; z-index:-1;}   
</style>

<script type="text/javascript">
	  var reqId = null;  
	  $(document).ready(function(){
		     $.ajaxSetup ({ cache:false,async: false });
			
		     // 归档-------------------------------------------------------------------------
			 $("#statusSub").click(function(){
				  $.post("<%=basePath%>allreq/edit.do", {id:$("#id").val(),status:'closed'}, function(data) {
						var result = $.parseJSON(data);
						if(result.code == 1) {
							alert("状态修改成功！");
						} else {
							alert(result.msg);
						}
				 });
		     });
			 // 归档结束---------------------------------------------------------------------
			 
		     // 回复信息---------------------------------------------------------------------
			 $('#commentForm').submit(function(){
				    if(isEmpty($("#comment").val()))
				    { 
				    	alert("回复内容不能为空！"); 
				        return false;
				    }
	                $.ajax({
	                    url: "<%=basePath%>myreq/comment.do",   // 提交的页面
	                    data: $('#commentForm').serialize(),    // 从表单中获取数据
	                    type: "POST",                           // 设置请求类型为"POST"，默认为"GET"
	                    dataType: 'json',
	                    error: function(XMLHttpRequest, textStatus, errorThrown) {
	                          alert(XMLHttpRequest.status);
	                    },
	                    success: function(data) {
	                    	if(data.code == 1) {
	                    		 $("#allComment").prepend(
						    			   "<table style=' width: 83%'>"
						    			 +"   <tr>"
						    			 +"      <td ><label>"+ data.createTime+"</label>"
						    			 +"      &nbsp;&nbsp;&nbsp; <font color='red'>"+$("#usercnname").val()+"</font></td>"
						    			 +"   </tr>"
						    			 +"   <tr>"
						    			 +"      <td class='word' >	<span style='color:#00A;'>"+$("#comment").val()+"</span></td>"
						    			 +"   </tr>"
						    			 +" </table>"
						    	  );
								 $('#comment').val('');
	                        }}
	                    });
	                return false;
	            });
		    
		    //回复信息结束---------------------------------------------------------------------------
			
		    //分发----------------------------------------------------------------------------------
		        $("#handoutSub").click(function(){
		        	var values = null;
		        	$("input[name='hands']:checkbox:checked").each(function(){ 
		        		if(values == null)
		        			values = $(this).val();
		        		else
		        		    values +=","+$(this).val() ;
		        	}) ;
		        	if(values == null) 
		     	    { 
		     	    	alert("接收端不能为空！"); 
		     	    	return false;
		     	    }
		        	if(curReqId == null)
		        	{
		        		alert("请选择需求");
		        		return false;
		        	}
		     	    else{
		     			$.get("allreq/handout.do", {id:curReqId,values:values}, function(data) {
		     				var result = $.parseJSON(data);
		     				if(result.code == 1) {
		     					alert("分发成功!");
		     					document.getElementById('light').style.display='none';
		    		    		document.getElementById('DivLocker').style.display='none';
		     				} else {
		     					alert(result.msg);
		     				}
		     			});
		     	    }
		       });
		    //分发结束------------------------------------------------------------------------------
	          
		    //取消分发------------------------------------------------------------------------------
		       $("#cancel").click(function(){
		    	   cancel();
				   document.getElementById('light').style.display='none';

		       });
		       $("#cancel1").click(function(){
		    	   cancel();
				   document.getElementById('passdiv').style.display='none';

		       });
		    //取消分发结束--------------------------------------------------------------------------
	  });
	  
	  //审核
	  function passing(status)
	  {
		  if(status != null)
		  {
			  $.post("<%=basePath%>allreq/edit.do", {id:$("#id").val(),status:status,reason:$("#notPassContent").val()}, function(data) {
					var result = $.parseJSON(data);
					if(result.code == 1) {
						alert("操作成功！");
						document.getElementById('passdiv').style.display='none';
    		    		document.getElementById('DivLocker').style.display='none';
					} else {
						alert(result.msg);
					}
			 });
		  }
	  }
	  //单击分发连接
	  function handout(id) {
	    	curReqId = id;
	    	document.getElementById('light').style.display='block';
	    	document.getElementById('DivLocker').style.display='block';
	    	divlocker();
	   }
	  
	  //审核失败
	  function passfail(id) {
	    	curReqId = id;
	    	document.getElementById('passdiv').style.display='block';
	    	document.getElementById('DivLocker').style.display='block';
	    	divlocker();
	   }
	  //遮罩
	  function divlocker(){
			$('#DivLocker').css({
    	        "position": "absolute",
    	        "background-color": "#000000",
    	        "height": function () { return $(document).height(); },
    	        "filter": "alpha(opacity=30)",
    	        "opacity": "0.3",
    	        "overflow": "hidden",
    	        "width": function () { return $(document).width(); },
    	        "z-index": "999"
            });
	  }
	  //取消遮罩
	  function cancel()
	  {
 		   document.getElementById('DivLocker').style.display='none';
	  }
	   //返回列表页面
	  function btn_return(){
		   var qs = $("#qs").val();
	       window.location.href="<%=basePath%>allreq/list.do?" + qs;
	  }
	</script>
</head>
<body>
	<div id="DivLocker" style="display: none" >
	    <iframe class="T_iframe"></iframe>  
    </div>
	<div class="divlist">
	    <!-- 基本信息-------------------------------------------------------------------------->
		<div style="width:98%">
			<fieldset>
				<legend>基本信息：</legend>
						<table  style="table-layout:fixed;width:95%">
							<tr>
								<td width="15%" ><label>标题：</label> </td>
								<td colspan="3"> <input id="qs" name="qs" type="hidden" value="${qs}"/>
								   ${req.title}
								</td>
							</tr>
							<tr>
						         <td><label for="status">负责方：</label></td>
								 <td>
						               <c:forEach items="${sList}" var="s" varStatus="status">
										       <c:if test="${req.startStatus == s.value}">
										          ${s.name}
										       </c:if>
									   </c:forEach>
						         </td>        
						    </tr>
							<tr>
								<td><label >发起人：</label></td>
								<td >
								 ${req.cnName}
								</td>
								<td  width="15%"><label >当前状态：</label></td>
								<td >
							       <c:forEach items="${itemList}" var="item" varStatus="status">
								       <c:if test="${req.status == item.value}">
								         ${item.name}
								       </c:if>
								   </c:forEach>
								</td>
							</tr>
							<tr>
								<td><label >发起时间：</label></td>
								<td>
								   <fmt:formatDate value="${req.createTime}" type="both"  dateStyle="medium" timeStyle="medium" />
								</td>
								<td width="15%"><label >期望完成时间：</label></td>
								<td>
								   <fmt:formatDate value="${req.expPerTime}" type="both"  dateStyle="medium" timeStyle="medium" /> 
								</td>
							</tr>
							<tr>
								<td><label>需求内容：</label> </td>
								<td colspan="3"> 
								    <textarea name="content" readonly="readonly" id="content" cols="60" rows="8"><c:out value="${req.content}"></c:out>
									</textarea>
								</td>
							</tr>
							<c:forEach items="${attList}" var="att" varStatus="status">
							  <tr>
							    <c:if test="${status.count == 1}">
								   <td><label>相关文件：</label> </td>
								</c:if>
								<c:if test="${status.count!=1}">
								   <td></td>
								</c:if>
								<td colspan="3"> 
								   <a href="<%=basePath%>myreq/download.do?fileName=${att.name}&path=${att.path}">${att.name}</a>
								</td>
							  </tr>
							</c:forEach>
						</table>
			</fieldset>
		</div>
	    <!-- 基本信息结束-------------------------------------------------------------------------->
	    
	    <!-- 处理情况------------------------------------------------------------------------------>
		<div style="width:98%">
			<fieldset>
				<legend>处理情况：</legend>
						<table style="table-layout:fixed;width:95%">
							<c:if test="${req.reqType != null}">
								<tr>
									<td width="15%"><label>类别：</label> </td>
									<td width="35%"> 
						                <c:forEach var="t" items="${typeList}">
						                   <c:if test="${t.id == req.reqType}">
						                       ${t.name}
						                   </c:if>
						                </c:forEach>
									</td>
									<td width="15%"><label>负责人：</label> </td>
									<td width="35%"> 
									   ${principal}
									</td>
								</tr>
					    	</c:if>
						
							<tr>
								<td>操作：</td>
								<td colspan="3"> 
								      <input type="hidden" id="id" name="id" value="${req.id}"/>
							          <input type="hidden" id="title" name="title" value="${req.title}"/>
							           <c:if test="${req.status == 'processed'}">
									    <input type="button" id="statusSub" value="归档" style="width: 80px;" /> 
									     &nbsp;
									   </c:if> 
									   <c:if test="${req.status != 'notPass' && req.status != 'submitted' }">
										    <p:chkPri actionUrl="allreq/handout.do">    
										      <input type="button" id="btn_handout"   onclick="javascript:handout('${req.id}'); return false;" value="分发" style="width: 80px;" />
										    </p:chkPri> 
									   </c:if> 
									     &nbsp;
									       <p:chkPri actionUrl="allreq/pass.do">    
									          <input type="button" id="pass"  onclick="javascript:passing('pass');return false;" value="审核成功" style="width: 80px;" /> 
									          &nbsp;
									       </p:chkPri> 
									       <p:chkPri actionUrl="allreq/notpass.do">   
									          <input type="button" id="notPass" onclick="javascript:passfail('${req.id}'); return false;" value="审核失败" style="width: 80px;" /> 
								              &nbsp; 
								           </p:chkPri> 
									   <input type="button" id="btn_back" value="返回" onclick="btn_return();" style="width: 80px;" />
								</td>
							</tr>
					</table>
			</fieldset>
		</div>
        <!-- 处理情况结束------------------------------------------------------------------------------>
	</div>
	
	 <div id="passdiv" class="white_content">
       <h4>添写理由</h4>
       <hr></hr>
	   <table style="table-layout:fixed">
	     <tr>
		       <td width="25%" valign="top" ><label for="title">理由：</label></td>
		       <td><textarea id = "notPassContent" rows="8" cols="30"></textarea></td>
	     </tr>
	     <tr>
		       <td></td>
		       <td>
		          <input type="button" id="subrevoke" onclick="javascript:passing('notPass');return false;" value ="提交" />
		          <input type="button" id="cancel1" value ="取消" />
		       </td>
	     </tr>
	  </table>
    </div>
	
	<!-- 分发处理---------------------------------------------------------------------------------->
	<div id="light" class="white_content">
        <fieldset>
           <legend>分发处理</legend>
             <div>
                  <c:forEach var="t" items="${typeList}">
	                  <input type="checkbox" name ="hands" id="hands" value="${t.id}" /><c:out value=" ${t.name}" ></c:out>
					  <br /><br />
                  </c:forEach>
                  <input type="button" id="handoutSub" value="提交" />&nbsp;
                  <input type="button" id="cancel" value="取消" />
		     </div> 
	  </fieldset> 
    </div>
    <!-- 分发处理结束------------------------------------------------------------------------------>
	
	<!-- 交流版 ----------------------------------------------------------------------------------->
    <div class="divcomment">
		<fieldset >
			<legend>交流板</legend>
		    <form id="commentForm" >
				<table style="width: 85%">
					<tr>
						<td ><textarea name="comment" id="comment" cols="40" rows="5"></textarea></td>
					    <td valign="bottom">
					      <input type="hidden" name="objectId" id="objectId" value="${req.id}">
					      <input type="submit" id="send" name="send" value="发表" />
					      <input type="hidden"  id="usercnname" value="${sessionScope.usercnname}">
					    </td>
					</tr>
				</table>
		    </form>
			<div id="allComment">
			   <c:forEach  items="${comList}" var="com">
					<table>
						<tr>
							<td>
								<label for="project">
								  <fmt:formatDate value="${com.createTime}" type="both"	dateStyle="medium" timeStyle="medium" />
								</label>
								&nbsp;&nbsp;&nbsp;
								<font color="red">${com.userCnname}</font>
							</td>
						
						</tr>
						<tr>
							<td class="word">
								<span style="color:#00A;">${com.content}</span>
							</td>
						</tr>
					</table>
				</c:forEach>
			</div>
		</fieldset>
	</div>
    <!-- 交流版结束 ---------------------------------------------------------------------------------------->
</body>
</html>